package com.yaowk.sfp.utils.verification.sms;

import com.libfintech.verification.service.ISmsService;
import com.libfintech.verification.service.Result;
import com.libfintech.verification.service.impl.YunpianConfig;
import com.libfintech.verification.util.VerificationUtil;
import com.yaowk.sfp.utils.verification.sms.def.DefSmsConfig;
import com.yaowk.sfp.utils.verification.sms.def.DefSmsService;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.PostConstruct;

/**
 * @author 小凯
 **/
public class SmsServiceImpl implements ISmsService {

    private ISmsService smsService;

    @Value("${yaowk.sms.platform:}")
    private String smsPlatform;

    @PostConstruct
    public void init() {
        switch (smsPlatform) {
            case "yunpian": {
                YunpianConfig yunpianConfig = new YunpianConfig();
                yunpianConfig.setImageCodeDisplayCount(Integer.MAX_VALUE);
                yunpianConfig.setRepositoryConfig(RedisRepositoryFactory.getRedisRepositoryConfig());
                smsService = VerificationUtil.createSmsService(yunpianConfig);
                break;
            }
            default: {
                smsService = new DefSmsService(new DefSmsConfig());
            }
        }
    }

    @Override
    public Result<String> send(String s, String s1, String s2, String s3) {
        return smsService.send(s, s1, s2, s3);
    }

    @Override
    public void send(String s, String s1) {
        smsService.send(s, s1);
    }

    @Override
    public Result<Void> verify(String s, String s1, String s2, String s3) {
        return smsService.verify(s, s1, s2, s3);
    }

    @Override
    public Result<String> refreshImageCode(String s, String s1) {
        return smsService.refreshImageCode(s, s1);
    }
}
